package com.china08.yxyapi.api.manage.sch.platform.users.teacher;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.model.resource.ItemModel;
import com.china08.yxyapi.service.yxweike.YxyLessonsSynLessonService;

import io.swagger.annotations.ApiOperation;

@RestController
public class SynLessonChapterAddItemContoller {

    @Autowired
    private YxyLessonsSynLessonService YxyLessonsSynLessonService;

    @ApiOperation(value = "同步课程-创建课程-章节添加课时")
    @RequestMapping(value = "/api_yw/manage/tec/lessons/synlesson/lesson/editor/chapteradditem", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public YxyApiRespModel precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody ReqModel reqModel) {
        YxyLessonsSynLessonService.chapterAddItem(reqModel.chapterId, reqModel.weikeList);
        return new YxyApiRespModel("操作成功");
    }

    protected static class ReqModel extends YxyApiReqModel {

        public String chapterId;

        public List<ItemModel> weikeList;

        @Override
        public void autoCheck() {
            Assert.notNull(StringUtils.defaultIfBlank(chapterId, null), "请填写章节ID");
            Assert.isTrue(weikeList != null && weikeList.size() > 0, "请填写微课ID");
        }
    }

}
